<template>
    <div>
        <div class="handle-box">
			<label class="label" >学号：</label>
			<el-input class="handle-input" v-model="form.student_number"/>
			<label class="label" >姓名：</label>
			<el-input class="handle-input" v-model="form.student_name"/>
			<label class="label" >开始时间：</label>
            <el-date-picker  style="width: 150px;" 
             type="date" v-model="form.startTime"></el-date-picker>
			<label class="label" >结束时间：</label>
            <el-date-picker style="width: 150px;" type="date"  v-model="form.endTime"></el-date-picker>
			<el-button color="#1c84c6" class="handle-btn"  @click="handleSearch">查询</el-button>
			<el-button color="#1c84c6"  @click="add">添加</el-button>                    
			
		</div>

         <el-table ref="multipleTableRef" 
            :header-cell-style="{color:'#2A62BC'}"
            :data="tableData"   
            style="width: 100%;" 
            border
            stripe 
            @selection-change="handleSelectionChange">
            <!-- <el-table-column   type="selection" width="35" /> -->
            <el-table-column  prop="student_number" label="学号"  align="center"></el-table-column>
            <el-table-column prop="student_name" label="姓名" align="center"></el-table-column>
            <el-table-column prop="discipline_time" label="违纪时间" align="center"></el-table-column>
            <el-table-column prop="presentation_condition" label="情况说明" align="center"></el-table-column>
            <el-table-column label="操作" width="150" align="center" >
                        <template #default="scope">
                            <el-row class="right-btn">
                            <el-tooltip content="没有此权限" placement="bottom" effect="light">
                                <el-button   disabled>
                                    <i class="iconfont icon-xiazai3"></i>
                                </el-button>
                            </el-tooltip>
                            <el-tooltip content="删除" placement="bottom" effect="light">
                                <el-button  style="color: red;" :icon="Delete"  @click="handleDelete(scope.row)">
                                </el-button>
                            </el-tooltip>
                            </el-row>
                            <!-- </el-button-group> -->
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
            <div class="pagination">
                    <el-pagination
                    :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :page-sizes="[5, 10, 15, 20]"
                        size="small"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageTotal"
                        @size-change="handleSizeChange"
                        @current-change="handlePageChange"/>
                </div>
              <!-- 添加违纪的弹窗 -->
              <el-dialog title="添加违纪记录" v-model="editVisible" width="20%" >
                    <el-form label-width="80px">
                        <el-form-item label="违纪学生:" disabled >
                            <el-input v-model="form.student_name"></el-input>
                        </el-form-item>
                        <el-form-item label="违纪时间:">
                            <el-date-picker v-model="form.discipline_time"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="附件说明:">
                           <el-input  type="file"></el-input>
                        </el-form-item>
                        <el-form-item label="情况说明:">
                           <el-input v-model="form.presentation_condition" type="textarea"></el-input>
                        </el-form-item>
                       
                    </el-form>
                    <template #footer>
                        <span class="dialog-footer">
                            <el-button @click="editVisible = false">关闭</el-button>
                            <el-button color="#2388c5" @click="saveEdit">确 定</el-button>
                        </span>
                    </template>
		</el-dialog> 
                
        </div>
    </template>
    
    <script setup lang="ts">
    import { ref, reactive } from 'vue';
    import { ElMessage, ElMessageBox } from 'element-plus';
    import { Delete, Edit, Search, CaretBottom } from '@element-plus/icons-vue';
    import { getStuViolation } from '../../../api/teaching' ;
    //分页字体
    const small = ref(true)
    // const size = ref<'default' | 'large' | 'small'>('default')
    
    //分页数据
    const query = reactive({
        pageIndex: 1,
        pageSize: 5,
    });
    //表格数据
    const tableData = ref();
    //总页数
    const pageTotal = ref(0);
    const multipleTableRef = ref()
    const state = reactive({
        multipleSelection:[]
    })
    
    // 获取表格数据  分页是数据截取  后台结合一起后  直接返回分页的后的数据
    const getData = () => {
        getStuViolation({pageCurrent:query.pageIndex,pageSize:query.pageSize}).then(res=>{
            console.log(res,"---res---")
            // tableData.value = res.data.
            let start  = (query.pageIndex-1)*query.pageSize;//开始位置
            let end =query.pageIndex*query.pageSize  ;//结束位置 数组的截取的时候 [start,end) suo所以不用-1
            tableData.value = res.data.slice(start,end);
            // tableData.value = res.data;
            pageTotal.value = res.data.length
        })
       
        
    };
    getData();
    //多选框权限
    const handleSelectionChange = (val) => {
      state.multipleSelection = val
    }
    // 分页导航
    const handleSizeChange = (val: number) => {
      // console.log(`${val} items per page`)
      query.pageSize = val;
      getData()
    }
    const handlePageChange = (val) => {
        query.pageIndex = val;
        console.log(val,"==")
        console.log(query.pageSize)
        getData()
    };
    
    // 删除单个操作
const handleDelete = (index) => {
	// 二次确认删除
	ElMessageBox.confirm('确定要删除吗？', '提示', {
		type: 'warning'
	})
	.then(() => {
		ElMessage.success('删除成功');
		//to.... 传递id 到后台 
		tableData.value.splice(index, 1);
		// 删除成功后
		// getData()
	})
	.catch(() => {});
};

//数据
const form =reactive({
    student_number:'',
    student_name: '',
    discipline_time:'',
    presentation_condition:'',
    startTime:'',
    endTime:'', 
})
//查询的方法
const handleSearch =()=>{
    //  to
}
//添加违纪记录
const editVisible = ref(false)
const  add=()=>{
  editVisible.value= true;
}
//保存到服务器
const saveEdit = ()=>{
    //。。。。
}
</script >
<style lang="less" scoped>
    .handle-box {
        margin-bottom: 20px;   
        .handle-btn{
            margin-left: 8px;
        }    
    }
    .handle-input {
      width:130px;
       padding: 6px;
    }
    .label{
       display: inline-block;
       max-width:100%;
       margin: 5px;
       font-weight: 600; 
       color: #676a6c;
       
    }
    .top-btn{
        float: right;
        .el-button{
            margin-left: 5px;
        }
    }
    .right-btn{
         justify-content:center;
        .el-button{
            height: 22px;
            // width: 60px;
            margin-right: 2px;
            padding: 1px 5px;
        }
    }
    
    
    </style>